
package com.example.xlzx.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xlzx.entity.CaseAnalysis;
import com.example.xlzx.result.Result;
import com.example.xlzx.service.ICaseAnalysisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 案例分析表 前端控制器
 * </p>
 *
 * @author 1
 * @since 2025-03-07
 */
@RestController
@Tag(name="案例分析信息")
@RequestMapping("/xlzx/caseAnalysis")
public class CaseAnalysisController {
    @Autowired
    private ICaseAnalysisService iCaseAnalysisService;

    @Operation(summary = "分页查询案例分析")
    @GetMapping("/page")
    public Result<IPage<CaseAnalysis>> pageCaseAnalysis(@RequestParam(required = false) String keyword, @RequestParam int page, @RequestParam int size) {
        Page<CaseAnalysis> pageParam = new Page<>(page, size);
        IPage<CaseAnalysis> caseAnalysisPageVoPage = iCaseAnalysisService.pageCaseAnalysis(pageParam, keyword);
        return Result.ok(caseAnalysisPageVoPage);
    }

    @Operation(summary = "添加案例分析")
    @PostMapping("/add")
    public Result<Boolean> addCaseAnalysis(@RequestBody CaseAnalysis caseAnalysis) {
        return Result.ok(iCaseAnalysisService.insertCaseAnalysis(caseAnalysis));
    }

    @Operation(summary = "根据id删除案例分析")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteCaseAnalysisById(@PathVariable Long id) {
        return Result.ok(iCaseAnalysisService.deleteCaseAnalysisById(id));
    }

    @Operation(summary = "修改案例分析")
    @PutMapping("/update")
    public Result<Boolean> updateCaseAnalysis(@RequestBody CaseAnalysis caseAnalysis) {
        return Result.ok(iCaseAnalysisService.updateCaseAnalysis(caseAnalysis));
    }

    @Operation(summary = "根据ID查询案例分析")
    @GetMapping("/get/{id}")
    public Result<CaseAnalysis> getCaseAnalysisById(@PathVariable Long id) {
        return Result.ok(iCaseAnalysisService.getCaseAnalysisById(id));
    }
}
